package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * Created by WF on 2019/9/18 10:54
 */
@Service
public class ProblemService {
    @Autowired
    private ProblemDao problemDao;
    //1.查询最新问题列表
    public PageResult<Problem> findnewList(String labelid, int page, int size) {
        //1.1)查询得到Page对象
        Page<Problem> problemPage = problemDao.findProblemsByLabelid(labelid,PageRequest.of(page-1,size));
        //1.2)将page对象转换pageResult对象
        return new PageResult<>(problemPage.getTotalElements(),problemPage.getContent());
    }
}
